﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ViewTopicDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		SE6.User curUsr = SessionMan.GetLoginUser();
		String textC = (String)Request.Form["textC"];
		String idStr=(String)Request["id"];
		Int32 id;
		if (!Int32.TryParse(idStr,out id))
		{
			SessionMan.SaveResult("该帖不存在，或已被删除!");
			Response.Redirect("Result.aspx");
		}
		Topic topic = DAMS.DataAccess.GetTopic(id);
		if (topic==null)
		{
			SessionMan.SaveResult("该帖不存在，或已被删除!");
			Response.Redirect("Result.aspx");
		}
		if (curUsr != null && curUsr.IsLeaveWordManager())
			op.InnerHtml = "<a class='button' href='par.aspx?t=6&id=" + idStr + "'>" +
				(topic.Top ? "取消置顶" : "置顶之") + "</a>" +
				"<a class='button' href='par.aspx?t=7&id=" + idStr + "'>" +
						(topic.IsExcellent() ? "取消加精" : "设为精华帖") + "</a>" +
						topic.GetDeleteURL(); ;
		String titleS = Request.Form["title"];
		if (Utility.Util.IsEmptyString(titleS))
			titleS = "回复：" + topic.Title;
		Boolean canLW = SystemMan.IsFunctionEnabled(FounctionType.LeaveWord);
		if (canLW)
		{
			if (textC != null && textC != "")
			{
				//新增回复
				if (curUsr != null || SessionMan.ValidateCheckCode((String)Request.Form["checkCode"]))
					feedBack.Text = BBS.AddReply(titleS, textC, Request);						
				else
					feedBack.Text = "请输入正确验证码！！！";
			}
			else if (curUsr == null)
				feedBack.Text = "提示：注册用户发表留言不用输入验证码哦，赶快<a href='Login.aspx' >登录</a>或<a href='Register.aspx' >注册</a>一个吧";
		}
		else
		{
			feedBack.CssClass = "cue";
			feedBack.Text = "系统正在维护中，留言吧暂时只能浏览帖子";
		}
		form1.Disabled = !canLW;
		if (!canLW)
			form1.InnerHtml = "";
		else
		{
			title.Value = titleS;
			topicID.Value = (String)Request["id"];
			if (curUsr == null)
			{
				//需要验证码
				checkCode.Text = "<tr><td>验证码:</td><td><input type='text' name='checkCode' id='checkCode' size='4'  onfocus='return RefreshCheckCode();'/>请输入右图中四位验证码，<img id='ccImg' src='CheckCodeImg.aspx'  alt = '验证码' /><a href='#' onclick='return RefreshCheckCode();'>看不清？换！</a></td></tr>";
			}
		}
		replys.InnerHtml = BBS.ViewReply(Request);
		navMenu.InnerHtml = GUI.NavMenu(PageClass.DetailTopics);
    }
}
